// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {

    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        // let xhr =new XMLHttpRequest();
        // xhr.onreadystatechange =function(){
        //     let response =xhr.responseText;
        //     console.log(response);
        // }
        // xhr.open("GET","http://118.24.115.231:3000/RankList",true);
        // xhr.send();


//         let par={
//             // uname:"王哥",
//             // score:100
//         };
//         par["uname"] ="wange";
//         par["score"] =100;
//         let temp= this.postDataFormat(par);
//
// console.log(temp);return;
        let xhr =new XMLHttpRequest();
        xhr.onreadystatechange =function(){
            let response =xhr.responseText;
            console.log(response);
        }


         let partern={
             // uname:"王哥",
             // score:100
         };
         partern["uname"] ="wange";
         partern["score"] =100;





         let value ="uname=wange&score=100";

         console.log("???"+this.testFun());
        // let data =new FormData();
        // data.append("uname","王哥");
        // data.append("score",100);
        xhr.open("POST","http://118.24.115.231:3000/Register",true);
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr.send(value);


    },

    testFun(){

        return "shaziba";
    },

    postDataFormat(obj){
        if(typeof obj != "object" ) {
             alert("输入的参数必须是对象");
             return;
       }

       // 支持有FormData的浏览器（Firefox 4+ , Safari 5+, Chrome和Android 3+版的Webkit）
         if(typeof FormData == "function") {
                var data = new FormData();
                for(var attr in obj) {
                         data.append(attr,obj[attr]);
                     }
                return data;
             }else {
            console.log("类型是"+typeof FormData);
                // 不支持FormData的浏览器的处理
                var arr = new Array();
                var i = 0;
                 for(var attr in obj) {
                       arr[i] = encodeURIComponent(attr) + "=" + encodeURIComponent(obj[attr]);
                    i++;
                  }
                return arr.join("&");
          }
     },

    // update (dt) {},
});
